﻿@page "/SlittingmachineUp"
@inject SlittingmachineServer slittingmachineUpServer
@using System.ComponentModel
@using AntDesign.TableModels
@inject ModalService _modalService
@inject MessageService _message
<h3>分切上料</h3>
<div>
    <Row>
        <Col Span="24">请选择分切机</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@DataList"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@selet"
                ValueName="@nameof(Slittingmachine_Entity.Deviceid)"
                LabelName="@nameof(Slittingmachine_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>选择[取满卷]缓存架</label>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@FullDataList"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@index"
                ValueName="@nameof(FullCache_Entity.Deviceid)"
                LabelName="@nameof(FullCache_Entity.Remark)">
        </Select>
        </Col>
    </Row>

    <Row>
        <Col Span="24">
        <label>选择[放空卷]缓存架</label>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@EmptyDataList"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@indexEmpty"
                ValueName="@nameof(EmptyCache_Entity.Deviceid)"
                LabelName="@nameof(EmptyCache_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>是否指定空缓存架</label>
        </Col>
    </Row>
    <Row>
        <Col Span="8" Push="8">
        <Switch style="width:100%" @bind-Value="@Flag"></Switch>
        </Col>
    </Row>
    <br>
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">提交分切上料任务</Button>
        </Col>
    </Row>
    <br>
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat2">提交分切上料任务(只需满卷)</Button>
        </Col>
    </Row>
</div>

@code {
    ObservableCollection<Slittingmachine_Entity> DataList { get; set; } = new ObservableCollection<Slittingmachine_Entity>();
    ObservableCollection<FullCache_Entity> FullDataList { get; set; } = new ObservableCollection<FullCache_Entity>();
    ObservableCollection<EmptyCache_Entity> EmptyDataList { get; set; } = new ObservableCollection<EmptyCache_Entity>();
    int selet { get; set; } = 0;
    int index { get; set; } = 0;
    int indexEmpty { get; set; } = 0;
    bool Flag = true;

    protected override async Task OnInitializedAsync()
    {
        var Slittingmachines = await slittingmachineUpServer.Getlist();
        if (Slittingmachines != null)
        {
            DataList.Clear();
            foreach (var item in Slittingmachines)
            {
                DataList.Add(item);
            }
        }
        var FullCaches = await slittingmachineUpServer.GetFulllist();
        if (FullCaches != null)
        {
            FullDataList.Clear();
            foreach (var item in FullCaches)
            {
                FullDataList.Add(item);
            }
        }
        var Emptycaches = await slittingmachineUpServer.GetEmptyist();
        if (Emptycaches != null)
        {
            EmptyDataList.Clear();
            foreach (var item in Emptycaches)
            {
                EmptyDataList.Add(item);
            }
        }

        base.OnInitialized();
    }
    private async Task Creat()
    {
        _modalService.Confirm(new ConfirmOptions()
        {
            Title = "提示",
            Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
OkText = "确认",
OnOk = async (e) =>
{
if (Flag)
{
int a = selet;
int c = index;
var aa = await slittingmachineUpServer.TaskCreatUp(selet, index, indexEmpty);
_message.Info(aa);
}
else
{
int a = selet;
int c = index;
var aa = await slittingmachineUpServer.TaskCreatUp(selet, index, 0);
_message.Info(aa);
}

},
CancelText = "取消",
Content = "是否提交？",
});
}
    private async Task Creat2()
    {
    _modalService.Confirm(new ConfirmOptions()
    {
    Title = "提示",
    Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
    OkText = "确认",
    OnOk = async (e) =>
    {
      
        int a = selet;
        int c = index;
        var aa = await slittingmachineUpServer.TaskCreatUp2(selet, index);
        _message.Info(aa);


    },
       CancelText = "取消",
       Content = "是否提交？",
});
}
}
